﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.Web;

namespace GONES.Tools.Common
{
    static public class CommonConfig
    {
        static public string GetValue(string type, string key)
        {
            string value = "";
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/KeyValue.xml"));
            XmlNodeList NodeList = xmlDoc.SelectNodes("root/" + type)[0].ChildNodes;
            for (int i = 0; i < NodeList.Count; i++)
            {
                if (NodeList[i].NodeType==XmlNodeType.Comment) 
                {
                    continue;
                }
                else
                {
                    if (NodeList[i].Attributes["key"].Value == key)
                    {
                        value= NodeList[i].Attributes["value"].Value;
                        break;
                    }
                }
            }
            return value;
        }

        static public string GetLValue(string type, string key)
        {
            string value = "";
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/KeyValue.xml"));
            XmlNodeList NodeList = xmlDoc.SelectNodes("root/" + type)[0].ChildNodes;
            for (int i = 0; i < NodeList.Count; i++)
            {
                if (NodeList[i].NodeType == XmlNodeType.Comment)
                {
                    continue;
                }
                else
                {
                    
                    if (key.IndexOf(NodeList[i].Attributes["key"].Value)==0)
                    {
                        value = NodeList[i].Attributes["value"].Value;
                        break;
                    }
                }
            }
            return value;
        }
    }
}
